//
//  BaseManager.m
//  HaloBear
//
//  Created by 刘继丹 on 16/12/7.
//  Copyright © 2016年 刘～丹. All rights reserved.
//

#import "BaseManager.h"
#import <CommonCrypto/CommonDigest.h>
#import <Foundation/Foundation.h>
#import "NSString+Common.h"
//#import "LoginResponse.h"
//#import "AdvertiseModel.h"
//#import "HBAlertUtils.h"
//#import "LoginViewController.h"

@implementation BaseManager

- (id)init{
    self = [super init];
    if (self) {
//        _timeString = [self getTimeString];
//        _paramsDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:_timeString,@"time", nil];
    }
    return self;
}

//-(NSDictionary<NSString *,NSString *> *)requestHeaderFieldValueDictionary
//{
//
//    NSString *imKey = @"81d0d60de8a693500b0a0769da0959ec";
//    
//    NSString *paramsStr;
//    
//    paramsStr = [self getParamsValueString];
//    
//    paramsStr = (__bridge_transfer  NSString*) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)paramsStr, NULL, (__bridge CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );
//    
//    NSString *md5Str = [paramsStr md5Str];
//    md5Str = [NSString stringWithFormat:@"%@%@",md5Str,imKey];
//    NSString *hashStr = [self getSha256String:md5Str];
//    
//    NSMutableDictionary *headers = [NSMutableDictionary dictionaryWithDictionary:[super requestHeaderFieldValueDictionary]];
//    [headers setObject:[NSString stringWithFormat:@"%@",hashStr] forKey:@"Http-Request-Halo-Sign"];
//    [headers setObject:[NSString stringWithFormat:@"%@",_timeString] forKey:@"Http-Request-Halo-Time"];
//    
////    NSString *header = [NSString stringWithFormat:@"Bearer %@",[LoginModel getToken]];
//
////    [headers setObject:header forKey:@"Authorization"];
////    if ([LocationManger getAddressCode]) {
////        [headers setObject:[LocationManger getAddressCode] forKey:@"Http-Request-Halo-Region"];
////    }
//
//    return headers;
//    
//}

//-(NSString *)getSha256String:(NSString *)srcString {
//    
//    const char *cstr = [srcString cStringUsingEncoding:NSUTF8StringEncoding];
//    NSData *data = [NSData dataWithBytes:cstr length:srcString.length];
//    
//    uint8_t digest[CC_SHA256_DIGEST_LENGTH];
//    
//    CC_SHA256(data.bytes, data.length, digest);
//    
//    NSMutableString* result = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
//    
//    for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
//        [result appendFormat:@"%02x", digest[i]];
//    }
//    
//    return result;
//}
//
//-(NSString *)getParamsValueString {
//    
//    //字典排序
//    NSArray *keys = [_paramsDic allKeys];
//    NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
//        return [obj1 compare:obj2 options:NSNumericSearch];
//    }];
//    
//    for (NSString *str in sortedArray) {
//        NSLog(@"%@", str);
//    }
//    
//    NSString *valueStr = [_paramsDic objectForKey:sortedArray.firstObject];
//    
//    for (int i = 0; i < sortedArray.count; i++) {
//        if (i == 0) {
//            continue;
//        }else{
//            NSString *value = [_paramsDic objectForKey:sortedArray[i]];
//            NSLog(@"[dict objectForKey:%@] === %@",sortedArray[i],value);
//            valueStr = [valueStr stringByAppendingString:value];
//        }
//    }
//    
//    return valueStr;
//}
//
//-(NSString *)getTimeString{
//    //时间戳 精确到秒
//    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];
//    NSTimeInterval a=[date timeIntervalSince1970];
//    NSString *time = [NSString stringWithFormat:@"%.0f", a];//转为字符型
//    return time;
//}


-(void)requestFailedFilter
{
//    NSLog(@"self.responseStatusCode=%ld",(long)self.responseStatusCode);
//    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
//    
//    if (self.responseStatusCode == 401) {
//        //401错误
//        LoginViewController *loginViewController = [LoginViewController new];
//        loginViewController.fromWhere = @"401错误";
//        loginViewController.loginBlock = ^(BOOL success){
//            if (_loginSuccessBlock) {
//                _loginSuccessBlock();
//            }
//        };
//        [keyWindow.rootViewController presentViewController:loginViewController animated:YES completion:nil];
//
//    }
    NSLog(@"requestFailedFilter====code = %ld",self.responseStatusCode);
}
@end
